package uf.audit.demo.controller;

import java.util.List;

import com.jfinal.plugin.activerecord.Record;

import uf.audit.demo.util.JSONUtil;
import uf.audit.tax.platform.core.annotation.Controller;
import uf.audit.tax.platform.core.db.DBProFacotry;

@Controller(url = "/wdsc", view = "/pages/wdsc")
public class WdscController extends BaseController {
	
	public void wdsc() {
		render("wdsc.html");
	}
	
	/**
	 * 
	 * 分页获取收藏的自行车
	 */
	 public void getWdsc() {
		Record rec = JSONUtil.parseRecord(getPostData());
		String curPage = rec.getStr("curPage");
		String itemsPage =rec.getStr("itemsPage");
		int iP = Integer.parseInt(itemsPage);
		int cP = Integer.parseInt(curPage)*2-iP;
		Object obj = this.getSession().getAttribute("user");
		Record rec1 = JSONUtil.parseRecord(JSONUtil.toJson(obj));
		String username = rec1.get("username");
		String getWdscSql = "select * from wdsc where username = ? limit ?,?";
		List<Record> list = DBProFacotry.getPro().find(getWdscSql,username,cP,iP);
		if(list.size()>0){
			renderJson(list);
		}
		
	 }
	 /**
		 * 
		 * 获取收藏的自行车
		 */
	 public void getAllWdsc() {
			Object obj = this.getSession().getAttribute("user");
			Record rec1 = JSONUtil.parseRecord(JSONUtil.toJson(obj));
			String username = rec1.get("username");
			String getWdscSql = "select count(*) num from wdsc where username = ?";
			List<Record> list = DBProFacotry.getPro().find(getWdscSql,username);
			renderJson(list);
			
		 }
}
